Page({
  data: {
    list:[],
    page:1,
    wu:false,
    items:[]
  },
  onLoad: function (options) {
    this.check_data();
  },
  check_data: function () {
    var user = wx.getStorageSync('user');
    var userId = user.id;
    const that = this;
    console.log(userId);
    wx.request({
      url: 'https://2016.bookgo.com.cn/wxapp/index/history/page/' + that.data.page +'?time=_t',
      data: {
        userId:userId,
        aid: 3
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        switch(res.data.code){
          case 101:
            that.setData({
              wu:false
            });
            var data = res.data.data;
            var items = that.data.list;
            for(var i = 0;i < data.length;i++){
              console.log(data[i])
              if(data[i].quit == 0){
                var ifan = (userId == data[i].ifan_id) ? 1 : 0;
                if(ifan == 1){
                  var issuccess = (data[i].ifan_id == data[i].who) ? 1 : 0;
                }else{
                  var issuccess = (data[i].icome_id == data[i].who) ? 1 : 0;
                }    
              }else{
                var issuccess = 2;
                // 判断是否是放弃的接收离座提醒
                var ifan = (data[i].irecive == 2) ? 0 : 1;
              }
              var item = { 
                            id:data[i].id,
                            seat_num: data[i].seat_num, 
                            time: data[i].time,
                            issuccess:issuccess,
                            ifan:ifan
                         }
              console.log(item)
              items.push(item);
            }
            that.setData({
              list : items
            });
            break;
          case 102:
            //  如果是第一页，则显示：无
            console.log('无');
            if (that.data.page == 1) {
              that.setData({
                wu: true
              });
            } else {
              wx.showToast({
                title: '没有更多了',
                icon: 'success',
                duration: 2000
              });
              return false;
            }
            break;
          default:
            wx.showModal({
              title: '提示',
              content: '请求错误，请重试',
              showCancel: false,
              success: function (res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                }
              }
            });
        }
      },
      fail: function (res) {
        wx.showModal({
          title: '提示',
          content: '请求错误，请重试',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            }
          }
        });
      },
      complete: function () {
        wx.stopPullDownRefresh();
      }
    })
    

  },
  formore:function(){
    var page = this.data.page + 1;
    this.setData({
      page:page
    });
    this.check_data();
  },
  onPullDownRefresh: function () {
    this.check_data();
  }

})
